//prepare moments from Silo to be read in by the model

//age profiles, unemployment transitions, additional moments, parent_inc-house_dist all good. Need to udpate attendance moments and provide completion matrices

//education transition probabilities
/*
import excel "$output/silo_output/educ_completions_corrected.xlsx", clear firstrow

//odrering of categories is weird. Update.
replace cat = 5 if cat == 3
replace cat = 3 if cat == 4
replace cat = 4 if cat == 5
sort ability cat
replace comp_1 = 1 if cat == 0
replace comp_2 = 0 if cat == 0
replace comp_3 = 0 if cat == 0
export delimited "$model/moments/educ_completions.csv", replace novarn //export
*/

***new attendance moments***

//overall attendance
import excel "$data/silo_output/attendance_tabs.xlsx", clear firstrow sheet("inc")
keep if _n == 20
drop ability parentinc
export delimited "$model/moments/attendance_all.csv", replace novarn



//attendance over ability
import excel "$data/silo_output/attendance_tabs.xlsx", clear firstrow sheet("inc")
keep if _n<4
drop parentinc
gen temp = cat_3
replace cat_3 = cat_4
replace cat_4 = temp
drop temp
ds cat*
foreach var in `r(varlist)'{
	replace `var' = `var'/100
}
export delimited "$model/moments/attendance_ability.csv", replace novarn

//attendance over parent inc q
import excel "$data/silo_output/attendance_tabs.xlsx", clear firstrow sheet("inc")
keep if _n>=4 & _n<=7
drop ability
gen temp = cat_3
replace cat_3 = cat_4
replace cat_4 = temp
drop temp
ds cat*
foreach var in `r(varlist)'{
	replace `var' = `var'/100
}
export delimited "$model/moments/attendance_inc.csv", replace novarn

//over parent inc q and ability
import excel "$data/silo_output/attendance_tabs.xlsx", clear firstrow sheet("inc")
keep if _n>=8
gen temp = cat_3
replace cat_3 = cat_4
replace cat_4 = temp
drop temp
ds cat*
foreach var in `r(varlist)'{
	replace `var' = `var'/100
}
drop if _n == 13
export delimited "$model/moments/attendance_inc_ability.csv", replace novarn


//over parent house q
import excel "$data/silo_output/attendance_tabs.xlsx", clear firstrow sheet("house")
keep if _n>=4 & _n<=7
drop ability
gen temp = cat_3
replace cat_3 = cat_4
replace cat_4 = temp
drop temp
ds cat*
foreach var in `r(varlist)'{
	replace `var' = `var'/100
}
export delimited "$model/moments/attendance_house.csv", replace novarn


//over parent house q and ability
import excel "$data/silo_output/attendance_tabs.xlsx", clear firstrow sheet("house")
keep if _n>=8
gen temp = cat_3
replace cat_3 = cat_4
replace cat_4 = temp
drop temp
ds cat*
foreach var in `r(varlist)'{
	replace `var' = `var'/100
}
drop if _n == 13
export delimited "$model/moments/attendance_house_ability.csv", replace novarn



//end of dofile